//
//  SwiftViewController.swift
//  testApp
//
//  Created by ColdMountain on 2017/1/16.
//  Copyright © 2017年 ColdMountain. All rights reserved.
//

import UIKit

let kPageSize = 10
let kPageInit = 10

class SwiftViewController: YNBaseViewController,UITableViewDelegate,UITableViewDataSource
{
    @IBOutlet weak var ui_tableView: UITableView!
    var hasNextPage:Bool!
    var m_messagesArray:NSMutableArray=[]
    var page:Int = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let nib = UINib(nibName:"XHSwiftCell", bundle:nil)
        self.ui_tableView.register(nib, forCellReuseIdentifier:XHSwiftCellIdentifier)
        PublicMethod.setExtraCellLineHidden(self.ui_tableView)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        self.postWithPage(page: self.page)
    }
    
    func postWithPage(page:Int){
//        postSwiftFuncation(IndexPage: UInt(page), success: { (data) -> (Void) in
//            self.m_messagesArray.addObjects(from: data as! [Any])
//            self.ui_tableView.reloadData()
//            print("返回成功。。。。。。。。")
//        }, failure: { (data) -> (Void) in
//            print("返回失败。。。。。。。。")
//        })
        
        postActivityFunction(IndexPage: UInt(page), success: { (data) -> (Void) in
            self.m_messagesArray.addObjects(from: data as! [Any])
            self.ui_tableView.reloadData()
            PromptAction.showSuccessPrompt("获取数据成功")
        }, failure: { (data) -> (Void) in
            
        })
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.m_messagesArray.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell: XHSwiftCell = self.ui_tableView.dequeueReusableCell(withIdentifier: XHSwiftCellIdentifier) as! XHSwiftCell
        let dic:NSDictionary = self.m_messagesArray[indexPath.row] as! NSDictionary
        let string = dic["bigtype"]
        let title = dic["title"]
        cell.ui_title.text=string as! String?
        cell.ui_content.text=title as! String?
        
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        PromptAction.showInfoPrompt("点击了第\(indexPath.row)行")
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        var height:CGFloat=0.0
        height=70
        
        return height
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
